package org.noka.select;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import org.nokatag.system.BugInfoWrint;
import org.nokatag.tagjava.NokaTag;
/**
 * 自定义下拉列表
 * @author rebin
 *
 */
public class SelectCustom extends  NokaTag{

	private static final long serialVersionUID = 7550610672397733696L;
	private  JspWriter jspOut =null;
	
	private String id = null;
	private String name = null;
	private String width = "120";
	private String height = "100";//下拉框高度
	private String value = null;
	private String text = null;
	private String readonly=null;//只读
	private String disabled = null;
	private String allownull="true";
	private String placeholder = null;
	
	public int doStartTag()throws JspException{
		try{
			jspOut= pageContext.getOut();
			HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
			StringBuilder body = new StringBuilder();
			body.append(potjs(request));//js框架
			body.append(selectCss(request));
			body.append(selectCustomjs(request));//select js
			String hei=LenNumber(height);
			body.append("<div id=\""+id+"_sDiv\">");
			body.append("<div id=\""+id+"_selectDiv\" style=\"float:left;\"></div>");
			body.append("<div id=\""+id+"_sboddiv\"  style=\"width:"+width+"px;overflow:auto;z-index: 999;background-color: #fff;display:none;position:absolute;overflow-x:hidden;height:"+(Long.parseLong(hei)+4)+"px;top:0px;left:0px;border: 1px solid #ddd;\">");
			jspOut.write(body.toString());
		}catch(Exception se){
			 BugInfoWrint.Print(se);
		}
		return EVAL_BODY_INCLUDE;
	}

	public int doEndTag() throws JspException {
		try {
			StringBuilder body = new StringBuilder();
			HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
			String hei=LenNumber(height);
			String basePath = basepath(request);
			body.append("</div>");
			body.append("</div>");
			body.append("<script type=\"text/javascript\">");
			//---------------显示树形菜单---------------------------
			body.append("Event.observe(document, 'dom:loaded', function() {");
			body.append("var sfg"+id+" = {");
			body.append("id:'"+id+"',");//id
			body.append("rurl:'"+basePath+"',");//根url
			body.append("text:'"+(text==null?"":text)+"',");//text
			body.append("name:'"+(name==null?id:name)+"',");//名字
			body.append("height:"+hei+",");//宽
			body.append("value:'"+(value==null?"":value)+"',");//值
			body.append("readonly:'"+(readonly==null?"":readonly)+"',");//只读
			body.append("disabled:'"+(disabled==null?"":disabled)+"',");
			body.append("allownull:"+allownull+",");
			body.append("placeholder:'"+(placeholder==null?"":placeholder)+"',");
			body.append("width:"+LenNumber(width));//宽
			body.append("};");
			body.append("var nr"+id+" = new nselectcustom(sfg"+id+");");
			body.append("nr"+id+".show();");
			body.append("});");
			body.append("</script>");
			pageContext.getOut().write(body.toString());
		} catch (IOException e) {
				e.printStackTrace();
		}
		return EVAL_PAGE;
	}

	public JspWriter getJspOut() {
		return jspOut;
	}


	public void setJspOut(JspWriter jspOut) {
		this.jspOut = jspOut;
	}


	public String getId() {
		return id;
	}


	public void setId(String id) {
		this.id = id;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public String getWidth() {
		return width;
	}


	public void setWidth(String width) {
		this.width = width;
	}


	public String getHeight() {
		return height;
	}


	public void setHeight(String height) {
		this.height = height;
	}


	public String getValue() {
		return value;
	}


	public void setValue(String value) {
		this.value = value;
	}


	public String getReadonly() {
		return readonly;
	}


	public void setReadonly(String readonly) {
		this.readonly = readonly;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getAllownull() {
		return allownull;
	}

	public void setAllownull(String allownull) {
		this.allownull = allownull;
	}

	public String getPlaceholder() {
		return placeholder;
	}

	public void setPlaceholder(String placeholder) {
		this.placeholder = placeholder;
	}

	public String getDisabled() {
		return disabled;
	}

	public void setDisabled(String disabled) {
		this.disabled = disabled;
	}
}